import { fileURLToPath, URL } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// 导入对应包
import ElementPlus from 'unplugin-element-plus/vite'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({importStyle:"sass"})
      ],
    }),
    // 按需定制主题配置
    ElementPlus({
      useSource: true,
    }),
  ],
  server: {
    port: 5173, // 前端项目运行端口
    proxy: {
      // 配置代理规则
      '/product-client': {
        target: 'http://localhost:6002', // 商品服务端口
        changeOrigin: true, // 允许跨域
        secure: false
      },
      '/merchant-client': {
        target: 'http://localhost:6013', // 商户服务端口
        changeOrigin: true, // 允许跨域
        secure: false
      },
      '/user-client': {
        target: 'http://localhost:6011', // 用户服务端口
        changeOrigin: true,
        secure: false
      },
      '/order': {
        target: 'http://localhost:6022', // 订单服务端口（与商品服务相同）
        changeOrigin: true,
        secure: false
      },
      '/sys-client': {
        target: 'http://localhost:6001', // 系统权限服务端口
        changeOrigin: true,
        secure: false
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 自动导入定制化样式文件进行样式覆盖
        additionalData: `
          @use "@/styles/element/index.scss" as *;
          @use "@/styles/var.scss" as *;
        `,
      }
    }
  }
})
